home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln1286.arc
/
BNCHMARK.ADA
/
FORTUNE.ADA
< prev
next >
Wrap
Text File
|
1986-09-06
|
3KB
|
124 lines
with RANDOM; use RANDOM;
with TEXT_IO; use TEXT_IO;
procedure FORTUNE is
--
-- Fortune cookie program
-- Author: Bruce A. Bergman, Aug 1986
-- These routines are released to the public domain for personal,
-- non-commercial purposes provided authorship remains unchanged.
-- Source available from Mark Petersen's Alpo-Net FIDO board at
-- (619) 741-3412, 300/1200/2400 8,N,1
--
package IIO is new INTEGER_IO(integer); use IIO;
------------------------------
-- declarations
------------------------------
type var_string is record
image : string (1..255);
length : natural;
end record;
cookie : natural;
cookie_jar : file_type;
fortune : var_string;
number_of_cookies : natural;
------------------------------
-- PUT_FORTUNE
------------------------------
--
-- Format fortune for 80 column screen.
--
procedure PUT_FORTUNE(fortune : in string) is
last : natural := fortune'length; -- find end
begin
--
-- Check to see if fortune longer than screen
--
if last > 78 then
last := 78;
--
-- Search backwards until we find a space,
-- then cut at that point (keeps fortune readable).
--
while (fortune(last) /= ' ') and (last > 1) loop
last := last - 1;
end loop;
--
-- Display it on screen.
--
put_line(fortune(1..last));
put_line(fortune(last+1..fortune'length));
else
--
-- Fortune doesn't need to be split.
--
put_line(fortune);
end if;
end PUT_FORTUNE;
begin
--
-- Open cookie jar.
-- Find out how many cookies inside.
--
open(cookie_jar, in_file, "cookie.jar");
get(cookie_jar, number_of_cookies);
--
-- Pick a cookie at random (add one so we don't
-- pick zero cookies).
--
cookie := random_number(number_of_cookies) + 1;
--
-- Sort through the pile until we find the
-- exact cookie we are looking for.
--
for i in 1..cookie loop
get_line(cookie_jar, fortune.image, fortune.length);
end loop;
--
-- Close cookie jar.
--
close(cookie_jar);
--
-- Display fortune.
--
put_fortune(fortune.image(1..fortune.length));
exception
when name_error => -- couldn't find cookie jar
put_line("Sorry, your cookie jar is empty!");
when numeric_error => -- error choosing a cookie
put_line("Sorry, the cookie jar is broken!");
end FORTUNE;